package com.appwoo.txtws.activity;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.adapter.ListViewCreator;
import com.appwoo.txtws.adapter.Page;
import com.appwoo.txtws.adapter.SimpleListAdapter;
import com.appwoo.txtws.app.App;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.RecordInfoBean;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.WebService;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.xmlpull.v1.XmlPullParserException;

public class WebSiteRecordSearch extends AppActivity
{
  private static final int DATE_DIALOG_ID;
  private SimpleListAdapter<RecordInfoBean> adapter;
  private boolean blDataTask;
  private EditText endDate;
  private List<RecordInfoBean> events;
  private int flag = 0;
  private boolean isFoot;
  private PageListView list;
  private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener()
  {
    public void onDateSet(DatePicker paramAnonymousDatePicker, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
      WebSiteRecordSearch.this.mYear = paramAnonymousInt1;
      WebSiteRecordSearch.this.mMonth = paramAnonymousInt2;
      WebSiteRecordSearch.this.mDay = paramAnonymousInt3;
      WebSiteRecordSearch.this.updateDisplay();
    }
  };
  private int mDay;
  private int mMonth;
  private int mYear;
  private ImageView moreset;
  private Page<RecordInfoBean> page = new Page();
  private ImageView search;
  private EditText startDate;

  private boolean CheckDate(String paramString1, String paramString2)
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    try
    {
      Date localDate1 = localSimpleDateFormat.parse(paramString1);
      Date localDate2 = localSimpleDateFormat.parse(paramString2);
      long l1 = localDate1.getTime();
      long l2 = localDate2.getTime();
      return l1 <= l2;
    }
    catch (ParseException localParseException)
    {
      localParseException.printStackTrace();
    }
    return true;
  }

  private void hideIM(View paramView)
  {
    try
    {
      ((InputMethodManager)getSystemService("input_method")).hideSoftInputFromWindow(paramView.getWindowToken(), 0);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  private void initActionBar()
  {
    setBarTitle(getResources().getString(2131428117));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        WebSiteRecordSearch.this.finish();
      }
    });
    this.moreset = ((ImageView)findViewById(2131492864).findViewById(2131493280));
    this.moreset.setImageResource(2130837828);
    LinearLayout.LayoutParams localLayoutParams = (LinearLayout.LayoutParams)this.moreset.getLayoutParams();
    localLayoutParams.height = 45;
    localLayoutParams.width = 45;
    this.moreset.setLayoutParams(localLayoutParams);
  }

  private void initAdapter()
  {
    this.list = ((PageListView)findViewById(2131493016));
    this.adapter = new SimpleListAdapter(this.page.getEntries(), new ListViewCreator()
    {
      public View createView(RecordInfoBean paramAnonymousRecordInfoBean, View paramAnonymousView, int paramAnonymousInt)
      {
        if (paramAnonymousView == null)
          paramAnonymousView = App.getLayoutInflater().inflate(2130903231, null);
        TextView localTextView1 = (TextView)paramAnonymousView.findViewById(2131493332);
        TextView localTextView2 = (TextView)paramAnonymousView.findViewById(2131493640);
        TextView localTextView3 = (TextView)paramAnonymousView.findViewById(2131493331);
        TextView localTextView4 = (TextView)paramAnonymousView.findViewById(2131493641);
        ((CheckBox)paramAnonymousView.findViewById(2131493011)).setVisibility(8);
        localTextView1.setText(paramAnonymousRecordInfoBean.getName());
        localTextView2.setText(paramAnonymousRecordInfoBean.getUrl());
        localTextView3.setText(paramAnonymousRecordInfoBean.getType());
        localTextView4.setText(paramAnonymousRecordInfoBean.getVisitedTime());
        return paramAnonymousView;
      }
    });
    this.list.setAdapter(this.adapter);
    this.list.setOnScrollListener(new AbsListView.OnScrollListener()
    {
      public void onScroll(AbsListView paramAnonymousAbsListView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
      {
      }

      public void onScrollStateChanged(AbsListView paramAnonymousAbsListView, int paramAnonymousInt)
      {
        if ((paramAnonymousInt == 0) && (paramAnonymousAbsListView.getLastVisiblePosition() == -1 + paramAnonymousAbsListView.getCount()) && (!WebSiteRecordSearch.this.list.getIsNoMore()) && (WebSiteRecordSearch.this.blDataTask))
        {
          WebSiteRecordSearch.this.list.prepareForRefreshMore();
          WebSiteRecordSearch.this.isFoot = true;
          WebSiteRecordSearch.this.loadingData(false);
        }
      }
    });
    this.list.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        WebSiteRecordSearch.this.list.prepareForRefreshMore();
        WebSiteRecordSearch.this.isFoot = true;
        WebSiteRecordSearch.this.loadingData(true);
      }
    });
    addOperation(new DataTask().execute(new String[] { "calls" }));
  }

  private void initView()
  {
    this.startDate = ((EditText)findViewById(2131493377));
    this.endDate = ((EditText)findViewById(2131493380));
    this.search = ((ImageView)findViewById(2131493269));
    String str = new SimpleDateFormat("yyyy-MM-dd").format(new Date(System.currentTimeMillis()));
    this.startDate.setText(str);
    this.endDate.setText(str);
    this.startDate.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        WebSiteRecordSearch.this.flag = 1;
        WebSiteRecordSearch.this.showDialog(0);
      }
    });
    this.endDate.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        WebSiteRecordSearch.this.flag = 2;
        WebSiteRecordSearch.this.showDialog(0);
      }
    });
    this.startDate.setOnFocusChangeListener(new View.OnFocusChangeListener()
    {
      public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
      {
        if (paramAnonymousBoolean)
        {
          WebSiteRecordSearch.this.flag = 1;
          WebSiteRecordSearch.this.hideIM(paramAnonymousView);
          WebSiteRecordSearch.this.showDialog(0);
        }
      }
    });
    this.endDate.setOnFocusChangeListener(new View.OnFocusChangeListener()
    {
      public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
      {
        if (paramAnonymousBoolean)
        {
          WebSiteRecordSearch.this.flag = 2;
          WebSiteRecordSearch.this.hideIM(paramAnonymousView);
          WebSiteRecordSearch.this.showDialog(0);
        }
      }
    });
    Calendar localCalendar = Calendar.getInstance();
    this.mYear = localCalendar.get(1);
    this.mMonth = localCalendar.get(2);
    this.mDay = localCalendar.get(5);
    updateDisplay();
    this.search.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (WebSiteRecordSearch.this.CheckDate(WebSiteRecordSearch.this.startDate.getText().toString(), WebSiteRecordSearch.this.endDate.getText().toString()))
        {
          WebSiteRecordSearch.this.page.removeAll();
          WebSiteRecordSearch.this.blDataTask = false;
          WebSiteRecordSearch.this.isFoot = false;
          WebSiteRecordSearch.this.page.firstPage();
          WebSiteRecordSearch.this.list.showFooterMoreView();
          WebSiteRecordSearch.this.list.setIsNoMore(false);
          WebSiteRecordSearch.this.initAdapter();
          return;
        }
        WebSiteRecordSearch.this.alertMessage(WebSiteRecordSearch.this.getString(2131428120));
      }
    });
  }

  private void loadingData(boolean paramBoolean)
  {
    if (paramBoolean)
      this.page.firstPage();
    while (true)
    {
      addOperation(new DataTask().execute(new String[] { "calls" }));
      return;
      this.page.nextPage();
    }
  }

  private void updateDisplay()
  {
    if (this.flag == 1)
      this.startDate.setText(new StringBuilder().append(this.mYear).append("-").append(1 + this.mMonth).append("-").append(this.mDay));
    while (this.flag != 2)
      return;
    this.endDate.setText(new StringBuilder().append(this.mYear).append("-").append(1 + this.mMonth).append("-").append(this.mDay));
  }

  protected void backKeyCallBack()
  {
    finish();
  }

  public void onBackPressed()
  {
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903181);
    initActionBar();
    initView();
    initAdapter();
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default:
      return null;
    case 0:
    }
    return new DatePickerDialog(this, this.mDateSetListener, this.mYear, this.mMonth, this.mDay);
  }

  protected void onResume()
  {
    super.onResume();
    this.adapter.notifyDataSetChanged();
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    String param;

    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.param = paramArrayOfString[0];
      RqSP localRqSP = new RqSP();
      String str1 = localRqSP.getLgDevAccount(WebSiteRecordSearch.this);
      String str2 = localRqSP.getLgDevId(WebSiteRecordSearch.this);
      try
      {
        if (this.param.equals("calls"))
          WebSiteRecordSearch.this.events = new WebService().getRecordInfo(str1, str2, null, WebSiteRecordSearch.this.page.getPageNo(), WebSiteRecordSearch.this);
        return null;
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        return null;
      }
      catch (XmlPullParserException localXmlPullParserException)
      {
        localXmlPullParserException.printStackTrace();
        return null;
      }
      catch (TimeOutException localTimeOutException)
      {
        localTimeOutException.printStackTrace();
        return null;
      }
      catch (NotFoundNetWorkException localNotFoundNetWorkException)
      {
        localNotFoundNetWorkException.printStackTrace();
      }
      return null;
    }

    protected void onPostExecute(String paramString)
    {
      if (this.param.equals("calls"))
      {
        if ((WebSiteRecordSearch.this.events == null) || (WebSiteRecordSearch.this.events.size() <= 0))
          break label171;
        WebSiteRecordSearch.this.page.addAllEntries(WebSiteRecordSearch.this.events);
        WebSiteRecordSearch.this.adapter.notifyDataSetChanged();
        WebSiteRecordSearch.this.list.onLoadMoreComplete();
        if (WebSiteRecordSearch.this.events.size() < WebSiteRecordSearch.this.page.getPageSize())
        {
          WebSiteRecordSearch.this.list.hideFotterMoreView();
          WebSiteRecordSearch.this.list.setIsNoMore(true);
        }
        WebSiteRecordSearch.this.events.clear();
      }
      while (true)
      {
        WebSiteRecordSearch.this.blDataTask = true;
        if (!WebSiteRecordSearch.this.isFoot)
        {
          WebSiteRecordSearch.this.closeProgress();
          WebSiteRecordSearch.this.isFoot = false;
        }
        super.onPostExecute(paramString);
        return;
        label171: WebSiteRecordSearch.this.list.hideFotterMoreView();
        WebSiteRecordSearch.this.list.setIsNoMore(true);
        WebSiteRecordSearch.this.alertMessage(WebSiteRecordSearch.this.getString(2131428119));
      }
    }

    protected void onPreExecute()
    {
      WebSiteRecordSearch.this.blDataTask = false;
      if (!WebSiteRecordSearch.this.isFoot)
        WebSiteRecordSearch.this.showProgress("");
      super.onPreExecute();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.WebSiteRecordSearch
 * JD-Core Version:    0.6.2
 */